package cn.jdy.plugins.service;

import java.util.HashMap;
import java.util.Map;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import cn.jdy.framework.db.hibernate.BaseDao;
import cn.jdy.framework.util.StringUtil;
import cn.jdy.plugins.entity.OperateLog;

/**
 * @author:
 * @title : 操作实现
 */
@Service
public class OperateLogService extends BaseDao<OperateLog> {


    public Map<String, Object> queryByPage(OperateLog operateLog, String fromDate, String toDate) {
        Assert.notNull(operateLog);
        DetachedCriteria dc = DetachedCriteria.forClass(super.entityClass);
        if(StringUtil.isNotEmpty(operateLog.getLogtype())){
            dc.add(Restrictions.like("logtype", "%"+operateLog.getLogtype().trim()+"%"));
        }
        if(StringUtil.isNotEmpty(fromDate)){
            if(StringUtil.isNotEmpty(toDate)){
                dc.add(Restrictions.between("opertime", fromDate, toDate));
            }else {
                dc.add(Restrictions.gt("opertime", fromDate));
            }
        }else if(StringUtil.isNotEmpty(toDate)){
            dc.add(Restrictions.lt("opertime", fromDate));
        }

        Map<String, Object> resp = new HashMap<>();
        resp.put("dataList", super.find(dc, operateLog.getiDisplayStart(), operateLog.getiDisplayLength()));
        Long count = super.count(dc);
        resp.put("iTotalDisplayRecords", count);
        resp.put("iTotalRecords", count);
        return resp;
    }

}
